/**
 入驻小区
 **/
 (function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            productDetailSpecInfo: {
                specs: [],
                productId: '',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('productDetailSpec', 'switch', function (_data) {
                $that.productDetailSpecInfo.productId = _data.productId;
                $that._loadProductDetailSpecData(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('productDetailSpec', 'notify',
                function (_data) {
                    $that._loadProductDetailSpecData(DEFAULT_PAGE, DEFAULT_ROWS);
                });
            vc.on('productDetailSpec', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    $that._loadProductDetailSpecData(_currentPage, DEFAULT_ROWS);
                });
        },
        methods: {
            _loadProductDetailSpecData: function (_page, _row) {
                let param = {
                    params: {
                        productId: $that.productDetailSpecInfo.productId,
                        page: 1,
                        row: 1,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };

                //发送get请求
                vc.http.apiGet('/product.queryProduct',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        let _productSpecValues = _json.data[0].productSpecValues;
                        if (_productSpecValues) {
                            _productSpecValues.forEach(item => {
                                let _productSpecDetails = item.productSpecDetails;
                                let _specValue = '';
                                if (_productSpecDetails) {
                                    _productSpecDetails.forEach(detail => {
                                        _specValue += (detail.detailValue + "/");
                                    });
                                }
                                item.specValue = _specValue;
                            });
                        }
                        $that.productDetailSpecInfo.specs = _productSpecValues;
                        vc.emit('productDetailSpec', 'paginationPlus', 'init', {
                            total: _json.records,
                            dataCount: _json.total,
                            currentPage: _page
                        });
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _qureyFeeDetailHisFee: function () {
                $that._loadProductDetailSpecData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
        }
    });
})(window.vc);